package masterjava.common.configuration;

import masterjava.common.logging.LoggingLevel;
import masterjava.common.logging.MasterLogger;
import masterjava.common.property.IPropertyListener;
import masterjava.common.property.Property;

import static masterjava.common.configuration.AppSetting.PROPS.*;

/**
 * User: GKislin
 * Date: 22.01.11
 * <p/>
 * Singleton
 */
public class AppSetting extends Setting {
    static final String PROPERTY_FILE_NAME = "app.properties";

    enum PROPS {
        appId, appName, vscRevision, loggingLevel, companyName
    }

    public final Property<String> APP_ID;

    public final Property<String> APP_NAME;

    public final Property<Integer> VSC_REVISION;

    public final Property<LoggingLevel> LOGGING_LEVEL;

    public final Property<String> COMPANY_NAME;

    protected AppSetting() {
        super(PROPERTY_FILE_NAME);
        initPropStore();
        APP_ID = createProp(appId);
        APP_NAME = createProp(appName);
        VSC_REVISION = createProp(vscRevision, 0);
        COMPANY_NAME = createProp(companyName);
        LOGGING_LEVEL = createProp(loggingLevel, LoggingLevel.INFO);
        LOGGING_LEVEL.addListener(new IPropertyListener<LoggingLevel>() {
            @Override
            public void update(Property<LoggingLevel> prop, LoggingLevel newValue) {
                MasterLogger.setRootLoggingLevel(newValue);
            }
        });
    }

    public static AppSetting get(){
        return get(PROPERTY_FILE_NAME, AppSetting.class);
    }
}
